<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script src="../vue.js"></script>
    </head>

    <body>
        <div id="app">
            <button @click="handler_base">修改基本数据类型</button>
            <h1>数据展示：字符串：{{msg}}数值：{{num}}布尔值：{{boolean1}}</h1>
            <hr />
            <button @click="handler_arr">修改数组数据类型</button>
            <h1>数据展示：{{person}}</h1>
            <hr />
            <button @click="handlder_obj">修改对象数据类型</button>
            <h1>数据展示：{{person1}}</h1>
        </div>
        <script>
            Vue.config.productionTip = false;

            const vm = new Vue({
                el: "#app",
                data() {
                    return {
                        msg: "hello",
                        num: 1,
                        boolean1: false,
                        person: ["小王", "大李", "小张", "王中王"],
                        person1: {
                            name: "laowang",
                            age: 18,
                            sex: "男",
                        },
                    };
                },
                methods: {
                    handler_base() {
                        this.msg = "hello001";
                        this.num = 3;
                        this.boolean1 = true;
                    },
                    handler_arr() {
                        // 1.使用变更原数组的方法
                        this.person.push("卡莎");
                        // 2.使用重新赋值的方法
                        this.person = this.person.map((item) => item + "a");
                    },
                    handlder_obj() {
                        // 1.直接更改对象
                        this.person1.name = "KASHA";
                        // 2.重新赋值（需要深浅拷贝改变原始地址）
                        this.person1 = { ...this.person1, age: 22 };
                        // 3.新增或删除调用vm.$set, Vue.set,vm.$delete, Vue.delete
                        this.$set(this.person1, "grade", 111);
                        Vue.delete(this.person1, "sex");
                    },
                },
            });
        </script>
    </body>
</html>
